using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Data.OracleClient;

namespace uk.co.tonyditchfield.tort.utility.conversion
{
    internal static class DbTypeMappingCollection
    {
        private static ICollection<DbTypeMapping> dbTypeMappings = null;
        private static bool ignoreUnicode = database.providers.ConnectionAttributes.ServerDetails().IgnoreUnicode;

        internal static ICollection<DbTypeMapping> DbTypeMappings()
        {
            if (dbTypeMappings == null)
            {
                dbTypeMappings = new List<DbTypeMapping>();
                dbTypeMappings.Add(new DbTypeMapping(typeof(bool), DbType.Boolean, SqlDbType.Bit, OracleType.Byte));
                dbTypeMappings.Add(new DbTypeMapping(typeof(byte), DbType.Byte, SqlDbType.TinyInt, OracleType.Byte));
                dbTypeMappings.Add(new DbTypeMapping(typeof(byte[]), DbType.Binary, SqlDbType.VarBinary, OracleType.Raw));
                dbTypeMappings.Add(new DbTypeMapping(typeof(char), OracleType.Char));
                dbTypeMappings.Add(new DbTypeMapping(typeof(DateTime), DbType.DateTime, SqlDbType.DateTime, OracleType.DateTime));
                dbTypeMappings.Add(new DbTypeMapping(typeof(Decimal), DbType.Decimal, SqlDbType.Decimal, OracleType.Number));
                dbTypeMappings.Add(new DbTypeMapping(typeof(double), DbType.Double, SqlDbType.Float, OracleType.Double));
                dbTypeMappings.Add(new DbTypeMapping(typeof(float), DbType.Single, SqlDbType.Real, OracleType.Float));
                dbTypeMappings.Add(new DbTypeMapping(typeof(Guid), DbType.Guid, SqlDbType.UniqueIdentifier, OracleType.Raw));
                dbTypeMappings.Add(new DbTypeMapping(typeof(Int16), DbType.Int16, SqlDbType.SmallInt, OracleType.Int16));
                dbTypeMappings.Add(new DbTypeMapping(typeof(Int32), DbType.Int32, SqlDbType.Int, OracleType.Int32));
                dbTypeMappings.Add(new DbTypeMapping(typeof(Int64), DbType.Int64, SqlDbType.BigInt, OracleType.Number));
                dbTypeMappings.Add(new DbTypeMapping(typeof(Int64), DbType.Int64, SqlDbType.BigInt, OracleType.Number));
                dbTypeMappings.Add(new DbTypeMapping(typeof(string), DbType.String,
                    ignoreUnicode == true ? SqlDbType.VarChar : SqlDbType.NVarChar,
                    ignoreUnicode == true ? OracleType.VarChar : OracleType.NVarChar));
                dbTypeMappings.Add(new DbTypeMapping(typeof(TimeSpan), DbType.Time, OracleType.DateTime));
                dbTypeMappings.Add(new DbTypeMapping(typeof(UInt16), DbType.UInt16, OracleType.UInt16));
                dbTypeMappings.Add(new DbTypeMapping(typeof(UInt32), DbType.UInt32, OracleType.UInt32));
                dbTypeMappings.Add(new DbTypeMapping(typeof(UInt64), DbType.UInt64, OracleType.Number));
            }
            return dbTypeMappings;
        }
    }
}
